package com.newthread.jdp.util;

public class MyStringUtil {
	public static String addString(String separator, String addStr,
			String needAddStr) {
		if (addStr == null) {
			addStr = "";
		}
		if (!addStr.contains(needAddStr)) {
			if (addStr != null && !(addStr.length() == 0)) {
				String[] temp = addStr.split(separator);
				String result = "";
				for (int i = 0; i < temp.length; i++) {
					if (i != temp.length) {
						result = result + temp[i] + separator;
					}
				}
				result = result + needAddStr;
				return result;
			} else {
				return needAddStr;
			}
		}
		return addStr;
	}

	public static String deleteString(String separator, String addStr,
			String needDelStr) {
		String[] temp = addStr.split(separator);
		String result = "";
		for (int i = 0; i < temp.length; i++) {
			if (i != temp.length) {
				if (!temp[i].equals(needDelStr)) {
					result = result + temp[i] + separator;
				}
			}
		}
		if (!result.equals("")) {
			result = (String) result.subSequence(0, result.length() - 1);
		} else {
			result = null;
		}
		return result;
	}
}
